#!usr/bin/env python
# -*- coding: utf-8 -*-
import frida, sys

def on_message(message, data):
    print(message)
    #for each in message['payload']:
    #    print(each)
    #print("[on_message] message:", message, "data:", data)
#processe#s = frida.get_remote_device().enumerate_processes()
#for process in processes:
#    print(process)
session = frida.get_remote_device().attach(14146)


jscode = """  
Java.perform(function() {
    var md5 = Java.use('com.bytedance.android.livesdk.chatroom.model.LiveRoomIDData');
    //send(md5.roomIdStr);
    console.log(md5.roomIdStr); 
    
    var methods = md5.class.getDeclaredMethods();
    
    for(var j = 0; j < methods.length; j++){
        var methodName = methods[j].getName();
        send(methodName);
        // hook methodNmae 这个类的所有方法（难点在于每个方法的参数是不同的）
        for(var k = 0; k < md5[methodName].overloads.length; k++){
            md5[methodName].overloads[k].implementation = function(){
                // 这是 hook 逻辑
                for(var i = 0; i < arguments.length; i++){
                    console.log(arguments[i]);
                }
                send(arguments);
                return this[methodName].apply(this, arguments);  // 重新调用
            }
        }

    }
}); 
"""

script = session.create_script(jscode)

script.on("message", on_message)
script.load()
#sys.stdin.read()
